---
# Configuration for the fedora-packages webapp

- name: install needed packages
  yum: pkg={{ item }} state=installed
  with_items:
  - fedora-packages
  - python-psycopg2
  - python-memcached
  - python-sqlalchemy0.8
  - redis
  tags:
  - packages

- name: Create some directories
  file: path={{ item }} state=directory owner=apache group=apache mode=755
  with_items:
  - /etc/fedoracommunity
  - /etc/fedoracommunity/yum_cache.repos.d
  - /var/cache/fedoracommunity  # the gluster role usually creates this one
  - /var/log/fedoracommunity

- name: Create some more locked down directories
  file: path={{ item }} state=directory owner=apache group=apache mode=700
  with_items:
  - /etc/pki/fedoracommunity

- name: Copy over the app config
  template: >
    src=packages-app.ini.j2
    dest=/etc/fedoracommunity/production.ini
    owner=apache group=apache mode=0600
  notify:
  - restart httpd

- name: Copy over the httpd config
  copy: >
    src=packages-httpd.conf
    dest=/etc/httpd/conf.d/fedora-packages.conf
    owner=root group=root
  notify:
  - restart httpd

- name: Copy over the yum config
  copy: >
    src=packages-yum.conf
    dest=/etc/fedoracommunity/yum-repo.conf
    owner=root group=root mode=0644
  notify:
  - restart httpd

- name: Copy over certs/public-keys, probably for talking with koji.
  copy: >
    src="{{private}}/files/packages/fedora-ca.cert"
    dest="/etc/pki/fedoracommunity/{{item}}"
    owner=apache
    group=apache
    mode=0644
  with_items:
  - fedora-server-ca.cert
  - fedora-upload-ca.cert

- name: permanently hotfix the distmappings file
  copy: >
    src=distmappings.py
    dest="{{pythonsitelib}}/fedoracommunity/search/distmappings.py"
    owner=root group=root mode=0644
  notify:
  - restart httpd

- name: start some helper services
  service: name="{{item}}" state=started enabled=yes
  with_items:
  - redis
  - fcomm-cache-worker

# Here's the indexer stuff
- name: Create cache structure
  file: >
    dest="/var/cache/fedoracommunity/{{item}}"
    state=directory
    owner=apache
    group=apache
    mode=0755
  with_items:
  - packages
  - rpm_cache
  - git.fedoraproject.org
  - packages/icons
  - packages/xapian
  - packages/xapian/search
  - packages/xapian/versionmap
  - packages/tmp
  - packages/tmp/icons
  - packages/tmp/rpms
  - packages/tmp/search
  - packages/tmp/versionmap
  - packages/tmp/var
  - packages/tmp/yum-cache
  when: install_packages_indexer

- name: Copy over the default icon
  copy: >
    src=package_128x128.png
    dest=/var/cache/fedoracommunity/packages/icons/package_128x128.png
  when: install_packages_indexer

- name: Copy some scripts for /usr/local
  copy: src="{{item}}" dest="/usr/local/bin/{{item}}" mode=0755
  with_items:
  - sync-yum
  when: install_packages_indexer

- name: Copy the indexer cronjobs
  copy: src="{{item}}" dest="/etc/cron.d/{{item}}"
  with_items:
  - cron-sync-yum
  - cron-sync-latest-builds
  - cron-sync-package-index
  - cron-flush-pkgs-cache
  when: install_packages_indexer

- name: Confygure Ye Olde Logge Rotatyr
  copy: src=cron_fcomm_log_rotate dest=/etc/logrotate.d/cron_fcomm_log_rotate
  when: install_packages_indexer


# Lastly, here's some selinux stuff.

- name: set some selinux booleans
  seboolean: name={{item}} persistent=yes state=yes
  with_items:
  - httpd_tmp_exec
  - httpd_can_network_memcache
  - httpd_can_network_connect
  - httpd_use_fusefs
